//
//  ApprovalRecordListViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/7/13.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit

class ApprovalRecordListViewController: BaseTableViewController {

    var source: Array<JSON> = []
    
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        self.tableView.register(UINib.init(nibName: "ApprovalRecordCell", bundle: Bundle.main), forCellReuseIdentifier: "ApprovalRecordCell")
        
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.tableView.reloadData()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.source.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if let cell = tableView.dequeueReusableCell(withIdentifier: "ApprovalRecordCell") as? ApprovalRecordCell {
            
            cell.model = source[indexPath.row]
            
            return cell
        }
        
        return UITableViewCell()
        
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header = UIView()
        header.backgroundColor = UIColor.dftBack
        return header
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        if let content = source[indexPath.row].contents?["approvalOpinion"]?.rawString() {
            
            let size = content.size(with: UIFont.systemFont(ofSize: 14), maxSize: CGSize(width: self.view.width - 44, height: 1000.0))
            
            return size.height + 70.0
        }
        
        return 0.0
        
    }

}
